package ca.etsmtl.log430.lab3;

import java.util.Observable;

/**
 * Upon notification, this class first lists the students and asks the
 * user to pick a student and enter the student's ID.  If the student's ID is valid, 
 * then the courses that the student has registered for will be listed.
 * 
 * @author A.J. Lattanze, CMU
 * @version 1.2, 2011-Feb-24
 */

/*
 * Modification Log **********************************************************
 * 
 * v1.2, R. Champagne, 2011-Feb-24 - Various refactorings, conversion of
 * comments to javadoc format.
 * 
 * v1.1, R. Champagne, 2002-Jun-19 - Adapted for use at ETS.
 * 
 * v1.0, A.J. Lattanze, 12/29/99 - Original version.
 * ***************************************************************************
 */

public class ListCoursesRegistered extends Communication {
	
	public ListCoursesRegistered( Integer registrationNumber, String componentName ) {
		super(registrationNumber, componentName);
	}

	/**
	 * The update() method is an abstract method that is called whenever the
	 * notifyObservers() method is called by the Observable class. First we check
	 * to see if the NotificationNumber is equal to this thread's
	 * RegistrationNumber. If it is, then we execute.
	 * 
	 * @see ca.etsmtl.log430.lab3.Communication#update(java.util.Observable,
	 *      java.lang.Object)
	 */
	public void update(Observable thing, Object notificationNumber) {
		Menus menu = new Menus();
		Displays display = new Displays();
		Student myStudent = new Student();

		if (registrationNumber.compareTo((Integer)notificationNumber) == 0) {
			/*
			 * First we use a Displays object to list all of the students. Then
			 * we ask the user to pick a student using a Menus object.
			 */
			addToReceiverList("ListStudentsComponent");
			signalReceivers("ListStudentsComponent");
			myStudent = menu.pickStudent(CommonData.theListOfStudents.listOfStudents);

			/*
			 * If the user selected an invalid student, then a message is
			 * printed to the terminal.
			 */
			if (myStudent != null) {
				display.displayStudentCoursesRegistered(myStudent);
			} else {
				System.out.println("\n\n *** Student not found ***");
			}
		}
		removeFromReceiverList("ListStudentsComponent");
	}
}